home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / unix / cpp / part01 next >
Encoding:
Internet Message Format  |  1990-01-18  |  46.9 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i022: cpp - a c preprocessor with some ANSI features, Part01/05
  5. Message-ID: <11030@xanth.cs.odu.edu>
  6. Date: 18 Jan 90 00:17:52 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: Olaf 'Rhialto' Seibert <U211344@HNYKUN11.BITNET>
  9. Lines: 1594
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11.  
  12. Submitted-by: Olaf 'Rhialto' Seibert <U211344@HNYKUN11.BITNET>
  13. Posting-number: Volume 90, Issue 022
  14. Archive-name: unix/cpp/part01
  15.  
  16. - A CPP (the Decus one, from a Fish disk) which has had some ANSI
  17.   features added. Also comes in handy for compiling NetHack 3.0,
  18.   which will be 'final' 'real soon now'.
  19.  
  20. Freely_Distributable=Greetings(Not_For_Any_Commercial_Purpose)->
  21.         Olaf.Seibert;
  22.  
  23. #!/bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 5)."
  30. # Contents:  Cpp.h cppdef.h makefile org org/contents org/cpp.rno
  31. #   org/make.boot org/makefile.txt org/readme org/readme.txt test.c
  32. # Wrapped by tadguy@xanth on Wed Jan 17 19:17:31 1990
  33. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  34. if test -f 'Cpp.h' -a "${1}" != "-c" ; then 
  35.   echo shar: Will not clobber existing file \"'Cpp.h'\"
  36. else
  37. echo shar: Extracting \"'Cpp.h'\" \(7570 characters\)
  38. sed "s/^X//" >'Cpp.h' <<'END_OF_FILE'
  39. X
  40. X/*
  41. X *    I n t e r n a l   D e f i n i t i o n s    f o r   C P P
  42. X *
  43. X * In general, definitions in this file should not be changed.
  44. X */
  45. X
  46. X#ifndef toupper
  47. X#define toupper(c) ((c) + ('A' - 'a'))
  48. X#endif /* no toupper */
  49. X#ifndef tolower
  50. X#define tolower(c) ((c) + ('a' - 'A'))
  51. X#endif /* no tolower */
  52. X
  53. X#ifndef TRUE
  54. X#define TRUE        1
  55. X#define FALSE        0
  56. X#endif
  57. X#ifndef EOS
  58. X/*
  59. X * This is predefined in Decus C
  60. X */
  61. X#define EOS        '\0'            /* End of string                */
  62. X#endif
  63. X#define EOF_CHAR    0        /* Returned by get() on eof     */
  64. X#define NULLST        ((char *) NULL) /* Pointer to nowhere (linted)  */
  65. X#define DEF_NOARGS    (-1)            /* #define foo vs #define foo() */
  66. X
  67. X/*
  68. X * The following may need to change if the host system doesn't use ASCII.
  69. X */
  70. X#define QUOTE_PARM    0x1C        /* Magic quoting operator    */
  71. X#define DEF_MAGIC    0x1D        /* Magic for #defines        */
  72. X#define TOK_SEP     0x1E        /* Token concatenation delim.    */
  73. X#define COM_SEP     0x1F        /* Magic comment separator    */
  74. X
  75. X/*
  76. X * Note -- in Ascii, the following will map macro formals onto DEL + the
  77. X * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
  78. X * be ok as long as PAR_MAC is less than 33).  Note that the last PAR_MAC
  79. X * value is reserved for string substitution.
  80. X */
  81. X
  82. X#define MAC_PARM    0x7F        /* Macro formals start here    */
  83. X#if PAR_MAC >= 33
  84. X    assertion fails -- PAR_MAC isn't less than 33
  85. X#endif
  86. X#define LASTPARM    (PAR_MAC - 1)
  87. X
  88. X/*
  89. X * Character type codes.
  90. X */
  91. X
  92. X#define INV        0        /* Invalid, must be zero    */
  93. X#define OP_EOE        INV        /* End of expression        */
  94. X#define DIG        1        /* Digit            */
  95. X#define LET        2        /* Identifier start        */
  96. X#define FIRST_BINOP    OP_ADD
  97. X#define OP_ADD        3
  98. X#define OP_SUB        4
  99. X#define OP_MUL        5
  100. X#define OP_DIV        6
  101. X#define OP_MOD        7
  102. X#define OP_ASL        8
  103. X#define OP_ASR        9
  104. X#define OP_AND        10        /* &, not &&            */
  105. X#define OP_OR        11        /* |, not ||            */
  106. X#define OP_XOR        12
  107. X#define OP_EQ        13
  108. X#define OP_NE        14
  109. X#define OP_LT        15
  110. X#define OP_LE        16
  111. X#define OP_GE        17
  112. X#define OP_GT        18
  113. X#define OP_ANA        19        /* &&                */
  114. X#define OP_ORO        20        /* ||                */
  115. X#define OP_QUE        21        /* ?                */
  116. X#define OP_COL        22        /* :                */
  117. X#define OP_CMA        23        /* , (relevant?)                */
  118. X#define LAST_BINOP    OP_CMA        /* Last binary operand        */
  119. X/*
  120. X * The following are unary.
  121. X */
  122. X#define FIRST_UNOP    OP_PLU        /* First Unary operand        */
  123. X#define OP_PLU        24        /* + (draft ANSI standard)      */
  124. X#define OP_NEG        25        /* -                */
  125. X#define OP_COM        26        /* ~                */
  126. X#define OP_NOT        27        /* !                */
  127. X#define LAST_UNOP    OP_NOT
  128. X#define OP_LPA        28        /* (                            */
  129. X#define OP_RPA        29        /* )                */
  130. X#define OP_END        30        /* End of expression marker    */
  131. X#define OP_MAX        (OP_END + 1)    /* Number of operators          */
  132. X#define OP_FAIL     (OP_END + 1)    /* For error returns            */
  133. X
  134. X/*
  135. X * The following are for lexical scanning only.
  136. X */
  137. X
  138. X#define QUO        65        /* Both flavors of quotation    */
  139. X#define DOT        66        /* . might start a number    */
  140. X#define SPA        67        /* Space and tab        */
  141. X#define BSH        68        /* Just a backslash        */
  142. X#define END        69        /* EOF                */
  143. X
  144. X/*
  145. X * These bits are set in ifstack[]
  146. X */
  147. X#define WAS_COMPILING    1        /* TRUE if compile set at entry */
  148. X#define ELSE_SEEN    2        /* TRUE when #else processed    */
  149. X#define TRUE_SEEN    4        /* TRUE when #if TRUE processed */
  150. X
  151. X/*
  152. X * Define bits for the basic types and their adjectives
  153. X */
  154. X
  155. X#define T_CHAR          1
  156. X#define T_INT          2
  157. X#define T_FLOAT       4
  158. X#define T_DOUBLE      8
  159. X#define T_SHORT      16
  160. X#define T_LONG         32
  161. X#define T_SIGNED     64
  162. X#define T_UNSIGNED    128
  163. X#define T_PTR        256        /* Pointer            */
  164. X#define T_FPTR        512        /* Pointer to functions     */
  165. X
  166. X/*
  167. X * The DEFBUF structure stores information about #defined
  168. X * macros.  Note that the defbuf->repl information is always
  169. X * in malloc storage.
  170. X */
  171. X
  172. Xtypedef struct defbuf {
  173. X    struct defbuf    *link;        /* Next define in chain */
  174. X    char        *repl;        /* -> replacement    */
  175. X    int        hash;        /* Symbol table hash    */
  176. X    int        nargs;        /* For define(args)     */
  177. X    char        name[1];    /* #define name     */
  178. X} DEFBUF;
  179. X
  180. X/*
  181. X * The FILEINFO structure stores information about open files
  182. X * and macros being expanded.
  183. X */
  184. X
  185. Xtypedef struct fileinfo {
  186. X    char        *bptr;        /* Buffer pointer    */
  187. X    int        line;        /* for include or macro */
  188. X    FILE        *fp;        /* File if non-null    */
  189. X    struct fileinfo *parent;    /* Link to includer    */
  190. X    char        *filename;    /* File/macro name    */
  191. X    char        *progname;    /* From #line statement */
  192. X    unsigned int    unrecur;    /* For macro recursion    */
  193. X    char        buffer[1];    /* current input line    */
  194. X} FILEINFO;
  195. X
  196. X/*
  197. X * The SIZES structure is used to store the values for #if sizeof
  198. X */
  199. X
  200. Xtypedef struct sizes {
  201. X    short    bits;            /* If this bit is set,        */
  202. X    short    size;            /* this is the datum size value */
  203. X    short    psize;            /* this is the pointer size    */
  204. X} SIZES;
  205. X/*
  206. X * nomacarg is a built-in #define on Decus C.
  207. X */
  208. X
  209. X#ifdef    nomacarg
  210. X#define cput        output        /* cput concatenates tokens    */
  211. X#else
  212. X#if COMMENT_INVISIBLE
  213. X#define cput(c)         { if (c != TOK_SEP && c != COM_SEP) putchar(c); }
  214. X#else
  215. X#define cput(c)         { if (c != TOK_SEP) putchar(c); }
  216. X#endif
  217. X#endif
  218. X
  219. X#ifndef nomacarg
  220. X#define streq(s1, s2)   (strcmp(s1, s2) == 0)
  221. X#endif
  222. X
  223. X/*
  224. X * Error codes.  VMS uses system definitions.
  225. X * Decus C codes are defined in stdio.h.
  226. X * Others are cooked to order.
  227. X */
  228. X
  229. X#if HOST == SYS_VMS
  230. X#include        <ssdef.h>
  231. X#include        <stsdef.h>
  232. X#define IO_NORMAL    (SS$_NORMAL | STS$M_INHIB_MSG)
  233. X#define IO_ERROR    SS$_ABORT
  234. X#endif
  235. X/*
  236. X * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
  237. X */
  238. X#ifndef IO_NORMAL
  239. X#define IO_NORMAL    0
  240. X#endif
  241. X#ifndef IO_ERROR
  242. X#define IO_ERROR    1
  243. X#endif
  244. X
  245. X/*
  246. X * Externs
  247. X */
  248. X
  249. Xextern int    line;            /* Current line number        */
  250. Xextern int    wrongline;        /* Force #line to cc pass 1    */
  251. Xextern char    type[];         /* Character classifier     */
  252. Xextern char    *tokenbuf;        /* Current input token        */
  253. Xextern int    tokenbsize;        /* Current size allocated in tokenbuf
  254. X                       (not counting 1 byte for zero) */
  255. Xextern int    instring;        /* TRUE if scanning string    */
  256. Xextern int    inmacro;        /* TRUE if scanning #define    */
  257. Xextern int    errors;         /* Error counter        */
  258. Xextern int    recursion;        /* Macro depth counter        */
  259. Xextern char    ifstack[BLK_NEST];    /* #if information        */
  260. X#define compiling ifstack[0]
  261. Xextern char    *ifptr;         /* -> current ifstack item    */
  262. Xextern char    *incdir[NINCLUDE];    /* -i directories        */
  263. Xextern char    **incend;        /* -> active end of incdir    */
  264. Xextern int    cflag;            /* -C option (keep comments)    */
  265. Xextern int    eflag;            /* -E option (ignore errors)    */
  266. Xextern int    nflag;            /* -N option (no pre-defines)   */
  267. Xextern int    wflag;            /* -W write #defines at end    */
  268. Xextern int    rec_recover;        /* unwind recursive macros    */
  269. Xextern char    *preset[];        /* Standard predefined symbols    */
  270. Xextern char    *magic[];        /* Magic predefined symbols    */
  271. Xextern FILEINFO *infile;        /* Current input file        */
  272. Xextern char    work[NWORK + 1];    /* #define scratch        */
  273. Xextern char    *workp;         /* Free space in work        */
  274. X#if    DEBUG
  275. Xextern int    debug;            /* Debug level            */
  276. X#endif
  277. Xextern int    keepcomments;        /* Don't remove comments if set */
  278. Xextern SIZES    size_table[];        /* For #if sizeof sizes     */
  279. Xextern char    *getmem();              /* Get memory or die.           */
  280. X
  281. X#ifndef amiga                /* Should track usage in cpp6.c */
  282. Xextern char    *incmem();              /* Increase size of block or die.  */
  283. X#endif
  284. X
  285. Xextern DEFBUF    *lookid();              /* Look for a #define'd thing   */
  286. Xextern DEFBUF    *defendel();            /* Symbol table enter/delete    */
  287. Xextern char    *savestring();          /* Stuff string in malloc mem.  */
  288. Xextern char    *strcpy();
  289. Xextern char    *strncpy();
  290. Xextern char    *strcat();
  291. Xextern char    *strrchr();
  292. Xextern char    *strchr();
  293. Xextern long    time();
  294. Xextern char    *sprintf();             /* Lint needs this              */
  295. Xextern void    free ();
  296. Xextern void    exit ();
  297. END_OF_FILE
  298. if test 7570 -ne `wc -c <'Cpp.h'`; then
  299.     echo shar: \"'Cpp.h'\" unpacked with wrong size!
  300. fi
  301. # end of 'Cpp.h'
  302. fi
  303. if test -f 'cppdef.h' -a "${1}" != "-c" ; then 
  304.   echo shar: Will not clobber existing file \"'cppdef.h'\"
  305. else
  306. echo shar: Extracting \"'cppdef.h'\" \(10891 characters\)
  307. sed "s/^X//" >'cppdef.h' <<'END_OF_FILE'
  308. X/* Special macro based debugging package */
  309. X/* Fred Fish, 14-Mar-86 */
  310. X#ifdef DBUG
  311. X#    include <local/dbug.h>
  312. X#else
  313. X#    define DBUG_ENTER(a1)
  314. X#    define DBUG_RETURN(a1) return(a1)
  315. X#    define DBUG_VOID_RETURN return
  316. X#    define DBUG_EXECUTE(keyword,a1)
  317. X#    define DBUG_2(keyword,format)
  318. X#    define DBUG_3(keyword,format,a1)
  319. X#    define DBUG_4(keyword,format,a1,a2)
  320. X#    define DBUG_5(keyword,format,a1,a2,a3)
  321. X#    define DBUG_PUSH(a1)
  322. X#    define DBUG_POP()
  323. X#    define DBUG_PROCESS(a1)
  324. X#    define DBUG_FILE (stderr)
  325. X#    define DBUG_SETJMP setjmp
  326. X#    define DBUG_LONGJMP longjmp
  327. X#endif
  328. X
  329. X#ifdef EMACS
  330. X
  331. X/* Use the Emacs config file to find out what type of machine */
  332. X
  333. X#define NO_SHORTNAMES
  334. X#include "../src/config.h"
  335. X
  336. X/* Convert Emacs's conventions for BIG_ENDIAN to cpp's convention.  */
  337. X#ifdef BIG_ENDIAN
  338. X#undef BIG_ENDIAN
  339. X#define BIG_ENDIAN TRUE
  340. X#else /* not BIG_ENDIAN */
  341. X#define BIG_ENDIAN FALSE
  342. X#endif /* BIG_ENDIAN */
  343. X
  344. X/* Emacs uses the names index and rindex and defines them as str(r)chr if nec;
  345. X   cpp uses the opposite convention.  Here we flush the macro definitions for
  346. X   Emacs and add the ones cpp wants.  */
  347. X
  348. X#ifdef index
  349. X#undef index
  350. X#undef rindex
  351. X#else /* index is not defined as a macro */
  352. X#define strchr index
  353. X#define strrchr rindex
  354. X#endif /* index is not defined as a macro */
  355. X
  356. X#define NBUFF 2048
  357. X#define NWORK 2048
  358. X
  359. X#endif /* EMACS */
  360. X
  361. X/*
  362. X *           S y s t e m     D e p e n d e n t
  363. X *        D e f i n i t i o n s     f o r     C P P
  364. X *
  365. X * Definitions in this file may be edited to configure CPP for particular
  366. X * host operating systems and target configurations.
  367. X *
  368. X * NOTE: cpp assumes it is compiled by a compiler that supports macros
  369. X * with arguments.  If this is not the case (as for Decus C), #define
  370. X * nomacarg -- and provide function equivalents for all macros.
  371. X *
  372. X * cpp also assumes the host and target implement the Ascii character set.
  373. X * If this is not the case, you will have to do some editing here and there.
  374. X */
  375. X
  376. X/*
  377. X * This redundant definition of TRUE and FALSE works around
  378. X * a limitation of Decus C.
  379. X */
  380. X#ifndef TRUE
  381. X#define TRUE            1
  382. X#define FALSE            0
  383. X#endif
  384. X
  385. X/*
  386. X * Define the HOST operating system.  This is needed so that
  387. X * cpp can use appropriate filename conventions.
  388. X */
  389. X#define SYS_UNKNOWN        0
  390. X#define SYS_UNIX        1
  391. X#define SYS_VMS         2
  392. X#define SYS_RSX         3
  393. X#define SYS_RT11        4
  394. X#define SYS_LATTICE        5
  395. X#define SYS_ONYX        6
  396. X#define SYS_68000        7
  397. X#define SYS_AMIGADOS        8
  398. X
  399. X#ifndef HOST
  400. X#ifdef    unix
  401. X#define HOST            SYS_UNIX
  402. X#else
  403. X#ifdef    vms
  404. X#define HOST            SYS_VMS
  405. X#else
  406. X#ifdef    rsx
  407. X#define HOST            SYS_RSX
  408. X#else
  409. X#ifdef    rt11
  410. X#define HOST            SYS_RT11
  411. X#else
  412. X#ifdef    amiga
  413. X#define HOST            SYS_AMIGADOS
  414. X#endif
  415. X#endif
  416. X#endif
  417. X#endif
  418. X#endif
  419. X#endif
  420. X
  421. X#ifndef HOST
  422. X#define HOST            SYS_UNKNOWN
  423. X#endif
  424. X
  425. X/*
  426. X * We assume that the target is the same as the host system
  427. X */
  428. X#ifndef TARGET
  429. X#define TARGET            HOST
  430. X#endif
  431. X
  432. X/*
  433. X * In order to predefine machine-dependent constants,
  434. X * several strings are defined here:
  435. X *
  436. X * MACHINE    defines the target cpu (by name)
  437. X * SYSTEM    defines the target operating system
  438. X * COMPILER    defines the target compiler
  439. X *
  440. X *    The above may be #defined as "" if they are not wanted.
  441. X *    They should not be #defined as NULL.
  442. X *
  443. X * LINE_PREFIX    defines the # output line prefix, if not "line"
  444. X *        This should be defined as "" if cpp is to replace
  445. X *        the "standard" C pre-processor.
  446. X *
  447. X * FILE_LOCAL    marks functions which are referenced only in the
  448. X *        file they reside.  Some C compilers allow these
  449. X *        to be marked "static" even though they are referenced
  450. X *        by "extern" statements elsewhere.
  451. X *
  452. X * OK_DOLLAR    Should be set TRUE if $ is a valid alphabetic character
  453. X *        in identifiers (default), or zero if $ is invalid.
  454. X *        Default is TRUE.
  455. X *
  456. X * OK_CONCAT    Should be set TRUE if # may be used to concatenate
  457. X *        tokens in macros (per the Ansi Draft Standard) or
  458. X *        FALSE for old-style # processing (needed if cpp is
  459. X *        to process assembler source code).
  460. X *
  461. X * OK_DATE    Predefines the compilation date if set TRUE.
  462. X *        Not permitted by the Nov. 12, 1984 Draft Standard.
  463. X *
  464. X * OK_SIZEOF    Permits sizeof in #if preprocessor expressions.
  465. X *        According to K&R V2 (page 232), this is not allowed.
  466. X *
  467. X * S_CHAR etc.    Define the sizeof the basic TARGET machine word types.
  468. X *        By default, sizes are set to the values for the HOST
  469. X *        computer.  If this is inappropriate, see the code in
  470. X *        cpp3.c for details on what to change.  Also, if you
  471. X *        have a machine where sizeof (signed int) differs from
  472. X *        sizeof (unsigned int), you will have to edit code and
  473. X *        tables in cpp3.c (and extend the -S option definition.)
  474. X *
  475. X * CPP_LIBRARY    May be defined if you have a site-specific include directory
  476. X *        which is to be searched *before* the operating-system
  477. X *        specific directories.
  478. X */
  479. X
  480. X#if TARGET == SYS_LATTICE
  481. X/*
  482. X * We assume the operating system is pcdos for the IBM-PC.
  483. X * We also assume the small model (just like the PDP-11)
  484. X */
  485. X#define MACHINE         "i8086"
  486. X#define SYSTEM            "pcdos"
  487. X#endif
  488. X
  489. X#if TARGET == SYS_ONYX
  490. X#define MACHINE         "z8000"
  491. X#define SYSTEM            "unix"
  492. X#endif
  493. X
  494. X#if TARGET == SYS_VMS
  495. X#define MACHINE         "vax"
  496. X#define SYSTEM            "vms"
  497. X#define COMPILER        "vax11c"
  498. X#endif
  499. X
  500. X#if TARGET == SYS_RSX
  501. X#define MACHINE         "pdp11"
  502. X#define SYSTEM            "rsx"
  503. X#define COMPILER        "decus"
  504. X#endif
  505. X
  506. X#if TARGET == SYS_RT11
  507. X#define MACHINE         "pdp11"
  508. X#define SYSTEM            "rt11"
  509. X#define COMPILER        "decus"
  510. X#endif
  511. X
  512. X#if TARGET == SYS_AMIGADOS
  513. X#define MACHINE         "amiga", "m68000"
  514. X#define SYSTEM            "amigados"
  515. X#ifdef manx
  516. X#define COMPILER        "manx"
  517. X#endif
  518. X#ifdef lattice
  519. X#define COMPILER        "lattice"
  520. X#endif
  521. X#ifdef pdc
  522. X#define COMPILER        "pdc", "__PDC__"
  523. X#endif
  524. X#endif
  525. X
  526. X#if TARGET == SYS_68000
  527. X/*
  528. X * All three machine designators have been seen in various systems.
  529. X * Warning -- compilers differ as to sizeof (int).  cpp3 assumes that
  530. X * sizeof (int) == 2
  531. X */
  532. X#define MACHINE         "M68000", "m68000", "m68k"
  533. X#define SYSTEM            "unix"
  534. X#endif
  535. X
  536. X#if    TARGET == SYS_UNIX
  537. X#define SYSTEM            "unix"
  538. X#ifdef    pdp11
  539. X#define MACHINE         "pdp11"
  540. X#endif
  541. X#ifdef    vax
  542. X#define MACHINE         "vax"
  543. X#endif
  544. X#endif
  545. X
  546. X/*
  547. X * defaults
  548. X */
  549. X
  550. X#ifndef MSG_PREFIX
  551. X#define MSG_PREFIX        "cpp: "
  552. X#endif
  553. X
  554. X#ifndef LINE_PREFIX
  555. X#ifdef    decus
  556. X#define LINE_PREFIX        ""
  557. X#else
  558. X#define LINE_PREFIX        "line"
  559. X#endif
  560. X#endif
  561. X
  562. X/*
  563. X * OLD_PREPROCESSOR forces the definition of OK_DOLLAR, OK_CONCAT,
  564. X * COMMENT_INVISIBLE, and STRING_FORMAL to values appropriate for
  565. X * an old-style preprocessor.
  566. X */
  567. X
  568. X#if    OLD_PREPROCESSOR
  569. X#define OK_DOLLAR        FALSE
  570. X#define OK_CONCAT        FALSE
  571. X#define COMMENT_INVISIBLE    TRUE
  572. X#define STRING_FORMAL        TRUE
  573. X#endif
  574. X
  575. X/*
  576. X * RECURSION_LIMIT may be set to -1 to disable the macro recursion test.
  577. X */
  578. X#ifndef RECURSION_LIMIT
  579. X#define RECURSION_LIMIT 1000
  580. X#endif
  581. X
  582. X/*
  583. X * BITS_CHAR may be defined to set the number of bits per character.
  584. X * it is needed only for multi-byte character constants.
  585. X */
  586. X#ifndef BITS_CHAR
  587. X#define BITS_CHAR        8
  588. X#endif
  589. X
  590. X/*
  591. X * BIG_ENDIAN is set TRUE on machines (such as the IBM 360 series)
  592. X * where 'ab' stores 'a' in the high-bits and 'b' in the low-bits.
  593. X * It is set FALSE on machines (such as the PDP-11 and Vax-11)
  594. X * where 'ab' stores 'a' in the low-bits and 'b' in the high-bits.
  595. X * (Or is it the other way around?) -- Warning: BIG_ENDIAN code is untested.
  596. X * [I *seems* to be the other way around, according to the code /OIS]
  597. X */
  598. X#ifndef BIG_ENDIAN
  599. X#define BIG_ENDIAN        FALSE
  600. X#endif
  601. X
  602. X/*
  603. X * COMMENT_INVISIBLE may be defined to allow "old-style" comment
  604. X * processing, whereby the comment becomes a zero-length token
  605. X * delimiter.  This permitted tokens to be concatenated in macro
  606. X * expansions.    This was removed from the Draft Ansi Standard.
  607. X */
  608. X#ifndef COMMENT_INVISIBLE
  609. X#define COMMENT_INVISIBLE    FALSE
  610. X#endif
  611. X
  612. X/*
  613. X * STRING_FORMAL may be defined to allow recognition of macro parameters
  614. X * anywhere in replacement strings.  This was removed from the Draft Ansi
  615. X * Standard and a limited recognition capability added.
  616. X */
  617. X#ifndef STRING_FORMAL
  618. X#define STRING_FORMAL        FALSE
  619. X#endif
  620. X
  621. X/*
  622. X * OK_DOLLAR enables use of $ as a valid "letter" in identifiers.
  623. X * This is a permitted extension to the Ansi Standard and is required
  624. X * for e.g., VMS, RSX-11M, etc.   It should be set FALSE if cpp is
  625. X * used to preprocess assembler source on Unix systems.  OLD_PREPROCESSOR
  626. X * sets OK_DOLLAR FALSE for that reason.
  627. X */
  628. X#ifndef OK_DOLLAR
  629. X#define OK_DOLLAR        TRUE
  630. X#endif
  631. X
  632. X/*
  633. X * OK_CONCAT enables (one possible implementation of) token concatenation.
  634. X * If cpp is used to preprocess Unix assembler source, this should be
  635. X * set FALSE as the concatenation character, #, is used by the assembler.
  636. X */
  637. X#ifndef OK_CONCAT
  638. X#define OK_CONCAT        TRUE
  639. X#endif
  640. X
  641. X/*
  642. X * OK_DATE may be enabled to predefine today's date as a string
  643. X * at the start of each compilation.  This is apparently not permitted
  644. X * by the Draft Ansi Standard.
  645. X */
  646. X#ifndef OK_DATE
  647. X#define OK_DATE     TRUE
  648. X#endif
  649. X
  650. X/*
  651. X * OK_SIZEOF may be defined to allow sizeof(type) in #if expressions.
  652. X * Actually, it is none of the preprocessors business how large these
  653. X * things are, as they might be different with different compiler
  654. X * options. Also, according to K&R V2, page 232, it is nonstandard.
  655. X * This option was added in the PDC process, under no. *OIS*0.92*.
  656. X */
  657. X#ifndef OK_SIZEOF
  658. X#define OK_SIZEOF    FALSE
  659. X#endif
  660. X
  661. X/*
  662. X * Some common definitions.
  663. X */
  664. X
  665. X#ifndef DEBUG
  666. X#define DEBUG        FALSE
  667. X#endif
  668. X
  669. X/*
  670. X * The following definitions are used to allocate memory for
  671. X * work buffers.  In general, they should not be modified
  672. X * by implementors.
  673. X *
  674. X * PAR_MAC    The maximum number of #define parameters (31 per Standard)
  675. X *        Note: we need another one for strings.
  676. X * NBUFF    Input buffer size
  677. X * NWORK    Work buffer size -- the longest macro
  678. X *        must fit here after expansion.
  679. X * NEXP     The nesting depth of #if expressions
  680. X * NINCLUDE    The number of directories that may be specified
  681. X *        on a per-system basis, or by the -I option.
  682. X * BLK_NEST    The number of nested #if's permitted.
  683. X */
  684. X
  685. X#ifndef PAR_MAC
  686. X#define PAR_MAC        (31 + 1)
  687. X#endif
  688. X
  689. X#ifndef NBUFF
  690. X#define NBUFF            512
  691. X#endif
  692. X
  693. X#ifndef NWORK
  694. X#define NWORK            512
  695. X#endif
  696. X
  697. X#ifndef NEXP
  698. X#define NEXP            128
  699. X#endif
  700. X
  701. X#ifndef NINCLUDE
  702. X#define NINCLUDE          7
  703. X#endif
  704. X
  705. X#ifndef NPARMWORK
  706. X#define NPARMWORK        (NWORK * 2)
  707. X#endif
  708. X
  709. X#ifndef BLK_NEST
  710. X#define BLK_NEST        32
  711. X#endif
  712. X
  713. X
  714. X/*
  715. X * Some special constants.  These may need to be changed if cpp
  716. X * is ported to a wierd machine.
  717. X *
  718. X * NOTE: if cpp is run on a non-ascii machine, ALERT and VT may
  719. X * need to be changed.    They are used to implement the proposed
  720. X * ANSI standard C control characters '\a' and '\v' only.
  721. X * DEL is used to tag macro tokens to prevent #define foo foo
  722. X * from looping.  Note that we don't try to prevent more elaborate
  723. X * #define loops from occurring.
  724. X */
  725. X
  726. X#ifndef ALERT
  727. X#define ALERT            '\007'          /* '\a' is "Bell"       */
  728. X#endif
  729. X
  730. X#ifndef VT
  731. X#define VT            '\013'          /* Vertical Tab CTRL/K  */
  732. X#endif
  733. X
  734. X
  735. X#ifndef FILE_LOCAL
  736. X#ifdef    decus
  737. X#define FILE_LOCAL        static
  738. X#else
  739. X#ifdef    vax11c
  740. X#define FILE_LOCAL        static
  741. X#else
  742. X#define FILE_LOCAL                /* Others are global    */
  743. X#endif
  744. X#endif
  745. X#endif
  746. END_OF_FILE
  747. if test 10891 -ne `wc -c <'cppdef.h'`; then
  748.     echo shar: \"'cppdef.h'\" unpacked with wrong size!
  749. fi
  750. # end of 'cppdef.h'
  751. fi
  752. if test -f 'makefile' -a "${1}" != "-c" ; then 
  753.   echo shar: Will not clobber existing file \"'makefile'\"
  754. else
  755. echo shar: Extracting \"'makefile'\" \(4001 characters\)
  756. sed "s/^X//" >'makefile' <<'END_OF_FILE'
  757. X# Makefile for cpp
  758. X#
  759. X# On certain systems, such as Unix System III, you may need to define
  760. X# $(LINTFLAGS) in the make command line to set system-specific lint flags.
  761. X#
  762. X# This Makefile assumes cpp will replace the "standard" preprocessor.
  763. X# Delete the reference to -DLINE_PREFIX=\"\" if cpp is used stand-alone.
  764. X# LINEFIX is a sed script filter that reinserts #line -- used for testing
  765. X# if LINE_PREFIX is set to "".   Note that we must stand on our heads to
  766. X# match the # and a line had better not begin with $.  By the way, what
  767. X# we really want is
  768. X#    LINEFIX = | sed "s/^#/#line/"
  769. X#
  770. X#CPPDEFINE = -DLINE_PREFIX=\"\"
  771. X#LINEFIX = | sed "s/^[^ !\"%-~]/&line/"
  772. X#
  773. X# Define OLD_PREPROCESSOR non-zero to make a preprocessor which is
  774. X# "as compatible as possible" with the standard Unix V7 or Ultrix
  775. X# preprocessors.  This is needed to rebuild 4.2bsd, for example, as
  776. X# the preprocessor is used to modify assembler code, rather than C.
  777. X# This is not recommended for current development.  OLD_PREPROCESSOR
  778. X# forces the following definitions:
  779. X#   OK_DOLLAR        FALSE    $ is not allowed in variables
  780. X#   OK_CONCAT        FALSE    # cannot concatenate tokens
  781. X#   COMMENT_INVISIBLE    TRUE    old-style comment concatenation
  782. X#   STRING_FORMAL    TRUE    old-style string expansion
  783. X#
  784. X# The following kludge bypasses the need for Fred's cc program by
  785. X# invoking the cpp front end cpp preprocessor.    The intermediate file
  786. X# is stored in ram, pre-appended with an underscore.  Manx's cc program
  787. X# is then invoked on the intermediate file.  The amigados delete command
  788. X# kills the intermediate file.
  789. X
  790. X#OLDDEFINE = -DOLD_PREPROCESSOR=1
  791. XHOST = -Damiga -Dpdc
  792. XEMACS =
  793. XDEBUGFLAG =
  794. XLDFLAGS =
  795. X#
  796. X# DEFINES collects all -D arguments for cc and lint:
  797. X# Change DEFINES = $(CPPDEFINE) $(OLDDEFINE)
  798. X# for an old-style preprocessor.
  799. X# If being used for GNU Emacs, the macro EMACS will be defined as -DEMACS.
  800. X#
  801. XDEFINES = $(OLDDEFINE) $(EMACS) $(HOST)
  802. X
  803. XCC =        cc
  804. X#DEBUGFLAG =    -g
  805. XCFLAGS =    $(DEBUGFLAG) $(DEFINES) $(CPPDEFINE)
  806. XLIBS =        -lc32
  807. X
  808. X.c.o:
  809. X    OldCpp $(CFLAGS) $*.c ram:_$*.c
  810. X    cc +L -o $*.o ram:_$*.c
  811. X    delete ram:_$*.c
  812. X
  813. X# ** compile cpp
  814. X#
  815. XSRCS =    cpp1.c cpp2.c cpp3.c cpp4.c cpp5.c cpp6.c
  816. XOBJS =    cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o
  817. X
  818. Xcpp :    $(OBJS)
  819. X    ln -o Cpp $(LDFLAGS) $(OBJS) $(LIBS)
  820. X
  821. X#
  822. X# ** Test cpp by preprocessing itself, compiling the result,
  823. X# ** repeating the process and diff'ing the result.  Note: this
  824. X# ** is not a good test of cpp, but a simple verification.
  825. X# ** The diff's should not report any changes.
  826. X# ** Note that a sed script may be executed for each compile
  827. X#
  828. Xtest :
  829. X    cpp cpp1.c $(LINEFIX) >old.tmp1.c
  830. X    cpp cpp2.c $(LINEFIX) >old.tmp2.c
  831. X    cpp cpp3.c $(LINEFIX) >old.tmp3.c
  832. X    cpp cpp4.c $(LINEFIX) >old.tmp4.c
  833. X    cpp cpp5.c $(LINEFIX) >old.tmp5.c
  834. X    cpp cpp6.c $(LINEFIX) >old.tmp6.c
  835. X    $(CC) $(CFLAGS) old.tmp[123456].c
  836. X    a.out cpp1.c >new.tmp1.c
  837. X    a.out cpp2.c >new.tmp2.c
  838. X    a.out cpp3.c >new.tmp3.c
  839. X    a.out cpp4.c >new.tmp4.c
  840. X    a.out cpp5.c >new.tmp5.c
  841. X    a.out cpp6.c >new.tmp6.c
  842. X    diff old.tmp1.c new.tmp1.c
  843. X    diff old.tmp2.c new.tmp2.c
  844. X    diff old.tmp3.c new.tmp3.c
  845. X    diff old.tmp4.c new.tmp4.c
  846. X    diff old.tmp5.c new.tmp5.c
  847. X    diff old.tmp6.c new.tmp6.c
  848. X    rm a.out old.tmp[123456].* new.tmp[123456].*
  849. X
  850. X#
  851. X# A somewhat more extensive test is provided by the "clock"
  852. X# program (which is not distributed).  Substitute your favorite
  853. X# macro-rich program here.
  854. X#
  855. Xclock : clock.c cpp
  856. X    cpp clock.c $(LINEFIX) >temp.cpp.c
  857. X    cc temp.cpp.c -lcurses -ltermcap -o clock
  858. X    rm temp.cpp.c
  859. X
  860. X#
  861. X# ** Lint the code
  862. X#
  863. X
  864. Xlint :    $(SRCS)
  865. X    lint $(LINTFLAGS) $(DEFINES) $(SRCS)
  866. X
  867. X#
  868. X# ** Remove unneeded files
  869. X#
  870. Xclean :
  871. X    rm -f $(OBJS) cpp
  872. X
  873. X#
  874. X# ** Rebuild the archive files needed to distribute cpp
  875. X# ** Uses the Decus C archive utility.
  876. X#
  877. X
  878. Xarchc : archc.c
  879. X    $(CC) $(CFLAGS) archc.c -o archc
  880. X
  881. Xarchx : archx.c
  882. X    $(CC) $(CFLAGS) archx.c -o archx
  883. X
  884. Xarchive : archc
  885. X    archc readme.txt cpp.mem archx.c archc.c cpp.rno makefile.txt \
  886. X        cpp*.h >cpp1.arc
  887. X    archc cpp1.c cpp2.c cpp3.c >cpp2.arc
  888. X    archc cpp4.c cpp5.c cpp6.c >cpp3.arc
  889. X
  890. X#
  891. X# Object module dependencies
  892. X#
  893. X
  894. X$(OBJS) :       cpp.h cppdef.h
  895. END_OF_FILE
  896. if test 4001 -ne `wc -c <'makefile'`; then
  897.     echo shar: \"'makefile'\" unpacked with wrong size!
  898. fi
  899. # end of 'makefile'
  900. fi
  901. if test ! -d 'org' ; then
  902.     echo shar: Creating directory \"'org'\"
  903.     mkdir 'org'
  904. fi
  905. if test -f 'org/contents' -a "${1}" != "-c" ; then 
  906.   echo shar: Will not clobber existing file \"'org/contents'\"
  907. else
  908. echo shar: Extracting \"'org/contents'\" \(107 characters\)
  909. sed "s/^X//" >'org/contents' <<'END_OF_FILE'
  910. XAn implementation of cpp (C Preprocessor) as distributed
  911. Xby DECUS.  This version was done by Martin Minow.
  912. END_OF_FILE
  913. if test 107 -ne `wc -c <'org/contents'`; then
  914.     echo shar: \"'org/contents'\" unpacked with wrong size!
  915. fi
  916. # end of 'org/contents'
  917. fi
  918. if test -f 'org/cpp.rno' -a "${1}" != "-c" ; then 
  919.   echo shar: Will not clobber existing file \"'org/cpp.rno'\"
  920. else
  921. echo shar: Extracting \"'org/cpp.rno'\" \(8099 characters\)
  922. sed "s/^X//" >'org/cpp.rno' <<'END_OF_FILE'
  923. X.lm 8.rm 72.nhy
  924. X
  925. X.no autosubtitle .style headers 3,0,0
  926. X.pg.uc.ps 58,80.lm 8.rm 72
  927. X.hd
  928. X.hd mixed
  929. X.head mixed
  930. X
  931. X.st ########cpp#####C Pre-Processor
  932. X.pg
  933. X.hl 1 ^&C Pre-Processor\&
  934. X.s 2
  935. X.c ;*******
  936. X.c ;* cpp *
  937. X.c ;*******
  938. X.s 2
  939. X.lm +8
  940. X.s.i -8;NAME:    cpp -- C Pre-Processor
  941. X.s.f
  942. X.i -8;SYNOPSIS:
  943. X.s.nf
  944. Xcpp [-options] [infile [outfile]]
  945. X.s.f
  946. X.i -8;DESCRIPTION:
  947. X.s
  948. XCPP reads a C source file, expands macros and include
  949. Xfiles, and writes an input file for the C compiler.
  950. XIf no file arguments are given, CPP reads from stdin
  951. Xand writes to stdout.  If one file argument is given,
  952. Xit will define the input file, while two file arguments
  953. Xdefine both input and output files.  The file name "-"
  954. Xis a synonym for stdin or stdout as appropriate.
  955. X.s
  956. XThe following options are supported.  Options may
  957. Xbe given in either case.
  958. X.lm +16
  959. X.p -16
  960. X-C        If set, source-file comments are written
  961. Xto the output file.  This allows the output of CPP to be
  962. Xused as the input to a program, such as lint, that expects
  963. Xcommands embedded in specially-formatted comments.
  964. X.p -16
  965. X-Dname=value    Define the name as if the programmer wrote
  966. X.s
  967. X.nf
  968. X    _#define name value
  969. X.s
  970. X.fill
  971. Xat the start of the first file.  If "=value" is not
  972. Xgiven, a value of "1" will be used.
  973. X.s
  974. XOn non-unix systems, all alphabetic text will be forced
  975. Xto upper-case.
  976. X.p -16
  977. X-E        Always return "success" to the operating
  978. Xsystem, even if errors were detected.  Note that some fatal
  979. Xerrors, such as a missing _#include file, will terminate
  980. XCPP, returning "failure" even if the -E option is given.
  981. X.p -16
  982. X-Idirectory    Add this directory to the list of
  983. Xdirectories searched for _#include "..." and _#include <...>
  984. Xcommands.  Note that there is no space between the
  985. X"-I" and the directory string.  More than one -I command
  986. Xis permitted.  On non-Unix systems "directory" is forced
  987. Xto upper-case.
  988. X.p -16
  989. X-N        CPP normally predefines some symbols defining
  990. Xthe target computer and operating system.  If -N is specified,
  991. Xno symbols will be predefined.  If -N -N is specified, the
  992. X"always present" symbols, ____LINE____, ____FILE____, and ____DATE____
  993. Xare not defined.
  994. X.p -16
  995. X-Stext        CPP normally assumes that the size of
  996. Xthe target computer's basic variable types is the same as the size
  997. Xof these types of the host computer.  (This can be overridden
  998. Xwhen CPP is compiled, however.)  The -S option allows dynamic
  999. Xrespecification of these values.  "text" is a string of
  1000. Xnumbers, separated by commas, that specifies correct sizes.
  1001. XThe sizes must be specified in the exact order:
  1002. X.s
  1003. X.nf
  1004. X    char short int long float double
  1005. X.s
  1006. X.fill
  1007. XIf you specify the option as "-S*text", pointers to these
  1008. Xtypes will be specified.  -S* takes one additional argument
  1009. Xfor pointer to function (e.g. int (*)())
  1010. X.s
  1011. XFor example, to specify sizes appropriate for a PDP-11,
  1012. Xyou would write:
  1013. X.s
  1014. X.nf
  1015. X       c s i l f d func
  1016. X     -S1,2,2,2,4,8,
  1017. X    -S*2,2,2,2,2,2,2
  1018. X.s
  1019. X.fill
  1020. XNote that all values must be specified.
  1021. X.p -16
  1022. X-Uname        Undefine the name as if
  1023. X.s
  1024. X.nf
  1025. X    _#undef name
  1026. X.s
  1027. X.fill
  1028. Xwere given.  On non-Unix systems, "name" will be forced to
  1029. Xupper-case.
  1030. X.p -16
  1031. X-Xnumber    Enable debugging code.  If no value is
  1032. Xgiven, a value of 1 will be used.  (For maintenence of
  1033. XCPP only.)
  1034. X.s.lm -16
  1035. X.s
  1036. X.i -8;PRE-DEFINED VARIABLES:
  1037. X.s
  1038. XWhen CPP begins processing, the following variables will
  1039. Xhave been defined (unless the -N option is specified):
  1040. X.s
  1041. XTarget computer (as appropriate):
  1042. X.s
  1043. X.nf
  1044. X    pdp11, vax, M68000 m68000 m68k
  1045. X.fill
  1046. X.s
  1047. XTarget operating system (as appropriate):
  1048. X.s
  1049. X.nf
  1050. X    rsx, rt11, vms, unix
  1051. X.fill
  1052. X.s
  1053. XTarget compiler (as appropriate):
  1054. X.s
  1055. X.nf
  1056. X    decus, vax11c
  1057. X.fill
  1058. X.s
  1059. XThe implementor may add definitions to this list.
  1060. XThe default definitions match the definition of the
  1061. Xhost computer, operating system, and C compiler.
  1062. X.s
  1063. XThe following are always available unless undefined (or
  1064. X-N was specified twice):
  1065. X.lm +16
  1066. X.p -12
  1067. X____FILE____    The input (or _#include) file being compiled
  1068. X(as a quoted string).
  1069. X.p -12
  1070. X____LINE____    The line number being compiled.
  1071. X.p -12
  1072. X____DATE____    The date and time of compilation as
  1073. Xa Unix ctime quoted string (the trailing newline is removed).
  1074. XThus,
  1075. X.s
  1076. X.nf
  1077. X    printf("Bug at line _%s,", ____LINE____);
  1078. X    printf(" source file _%s", ____FILE____);
  1079. X    printf(" compiled on _%s", ____DATE____);
  1080. X.fill
  1081. X.s.lm -16
  1082. X.s
  1083. X.i -8;DRAFT PROPOSED ANSI STANDARD CONSIDERATIONS:
  1084. X.s
  1085. XThe current version of the Draft Proposed Standard
  1086. Xexplicitly states that "readers are requested not to specify
  1087. Xor claim conformance to this draft."  Readers and users
  1088. Xof Decus CPP should not assume that Decus CPP conforms
  1089. Xto the standard, or that it will conform to the actual
  1090. XC Language Standard.
  1091. X.s
  1092. XWhen CPP is itself compiled, many features of the Draft
  1093. XProposed Standard that are incompatible with existing
  1094. Xpreprocessors may be disabled.  See the comments in CPP's
  1095. Xsource for details.
  1096. X.s
  1097. XThe latest version of the Draft Proposed Standard (as reflected
  1098. Xin Decus CPP) is dated November 12, 1984.
  1099. X.s
  1100. XComments are removed from the input text.  The comment
  1101. Xis replaced by a single space character.  The -C option
  1102. Xpreserves comments, writing them to the output file.
  1103. X.s
  1104. XThe '$' character is considered to be a letter.  This is
  1105. Xa permitted extension.
  1106. X.s
  1107. XThe following new features of C are processed by CPP:
  1108. X.s.comment Note: significant spaces, not tabs, .br quotes #if, #elif
  1109. X.br;####_#elif expression    (_#else _#if)
  1110. X.br;####'_\xNNN'             (Hexadecimal constant)
  1111. X.br;####'_\a'                (Ascii BELL)
  1112. X.br;####'_\v'                (Ascii Vertical Tab)
  1113. X.br;####_#if defined NAME    1 if defined, 0 if not
  1114. X.br;####_#if defined (NAME)  1 if defined, 0 if not
  1115. X.br;####_#if sizeof (basic type)
  1116. X.br;####unary +
  1117. X.br;####123U, 123LU          Unsigned ints and longs.
  1118. X.br;####12.3L                Long double numbers
  1119. X.br;####token_#token         Token concatenation
  1120. X.br;####_#include token      Expands to filename
  1121. X.s
  1122. XThe Draft Proposed Standard has extended C, adding a constant
  1123. Xstring concatenation operator, where
  1124. X.s
  1125. X.nf
  1126. X    "foo" "bar"
  1127. X.s
  1128. X.fill
  1129. Xis regarded as the single string "foobar".  (This does not
  1130. Xaffect CPP's processing but does permit a limited form of
  1131. Xmacro argument substitution into strings as will be discussed.)
  1132. X.s
  1133. XThe Standard Committee plans to add token concatenation
  1134. Xto _#define command lines.  One suggested implementation
  1135. Xis as follows:  the sequence "Token1_#Token2" is treated
  1136. Xas if the programmer wrote "Token1Token2".  This could
  1137. Xbe used as follows:
  1138. X.s
  1139. X.nf
  1140. X    _#line 123
  1141. X    _#define ATLINE foo_#____LINE____
  1142. X.s
  1143. X.fill
  1144. XATLINE would be defined as foo123.
  1145. X.s
  1146. XNote that "Token2" must either have the format of an
  1147. Xidentifier or be a string of digits.  Thus, the string
  1148. X.s
  1149. X.nf
  1150. X    _#define ATLINE foo_#1x3
  1151. X.s
  1152. X.fill
  1153. Xgenerates two tokens: "foo1" and "x3".
  1154. X.s
  1155. XIf the tokens T1 and T2 are concatenated into T3,
  1156. Xthis implementation operates as follows:
  1157. X.s
  1158. X.nf
  1159. X  1. Expand T1 if it is a macro.
  1160. X  2. Expand T2 if it is a macro.
  1161. X  3. Join the tokens, forming T3.
  1162. X  4. Expand T3 if it is a macro.
  1163. X.s
  1164. X.fill
  1165. XA macro formal parameter will be substituted into a string
  1166. Xor character constant if it is the only component of that
  1167. Xconstant:
  1168. X.s
  1169. X.nf
  1170. X    _#define VECSIZE 123
  1171. X    _#define vprint(name, size) _\
  1172. X      printf("name" "[" "size" "] = {_\n")
  1173. X      ... vprint(vector, VECSIZE);
  1174. X.s
  1175. X.fill
  1176. Xexpands (effectively) to
  1177. X.s
  1178. X.nf
  1179. X      vprint("vector[123] = {_\n");
  1180. X.s
  1181. X.fill
  1182. XNote that this will be useful if your C compiler supports
  1183. Xthe new string concatenation operation noted above.
  1184. XAs implemented here, if you write
  1185. X.s
  1186. X.nf
  1187. X    _#define string(arg) "arg"
  1188. X      ... string("foo") ...
  1189. X.s
  1190. X.fill
  1191. XThis implementation generates "foo", rather than the strictly
  1192. Xcorrect ""foo"" (which will probably generate an error message).
  1193. XThis is, strictly speaking, an error in CPP and may be removed
  1194. Xfrom future releases.
  1195. X.s
  1196. X.i -8;ERROR MESSAGES:
  1197. X.s
  1198. XMany.  CPP prints warning or error messages if you try to
  1199. Xuse multiple-byte character constants (non-transportable)
  1200. Xif you _#undef a symbol that was not defined, or if your
  1201. Xprogram has potentially nested comments.
  1202. X.s
  1203. X.i -8;AUTHOR:
  1204. X.s
  1205. XMartin Minow
  1206. X.s
  1207. X.i -8;BUGS:
  1208. X.s
  1209. XThe _#if expression processor uses signed integers only.
  1210. XI.e, _#if 0xFFFFu < 0 may be TRUE.
  1211. X.s
  1212. X.lm 8.rm 72.nhy
  1213. X
  1214. END_OF_FILE
  1215. if test 8099 -ne `wc -c <'org/cpp.rno'`; then
  1216.     echo shar: \"'org/cpp.rno'\" unpacked with wrong size!
  1217. fi
  1218. # end of 'org/cpp.rno'
  1219. fi
  1220. if test -f 'org/make.boot' -a "${1}" != "-c" ; then 
  1221.   echo shar: Will not clobber existing file \"'org/make.boot'\"
  1222. else
  1223. echo shar: Extracting \"'org/make.boot'\" \(579 characters\)
  1224. sed "s/^X//" >'org/make.boot' <<'END_OF_FILE'
  1225. X# Note: ccx is a cc frontend that knows about the preprocessor.
  1226. X
  1227. XCC =        cc/ccx
  1228. XCFLAGS =    -DHOST=SYS_AMIGADOS -DOLD_PREPROCESSOR=1
  1229. XOBJS =        cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o
  1230. X
  1231. Xncpp :        $(OBJS)
  1232. X        $(CC) -o ncpp $(OBJS)
  1233. X
  1234. Xcpp1.o    :    cpp1.c cpp.h cppdef.h
  1235. X        $(CC) $(CFLAGS) -c cpp1.c
  1236. X
  1237. Xcpp2.o    :    cpp2.c cpp.h cppdef.h
  1238. X        $(CC) $(CFLAGS) -c cpp2.c
  1239. X
  1240. Xcpp3.o    :    cpp3.c cpp.h cppdef.h
  1241. X        $(CC) $(CFLAGS) -c cpp3.c
  1242. X
  1243. Xcpp4.o    :    cpp4.c cpp.h cppdef.h
  1244. X        $(CC) $(CFLAGS) -c cpp4.c
  1245. X
  1246. Xcpp5.o    :    cpp5.c cpp.h cppdef.h
  1247. X        $(CC) $(CFLAGS) -c cpp5.c
  1248. X
  1249. Xcpp6.o    :    cpp6.c cpp.h cppdef.h
  1250. X        $(CC) $(CFLAGS) -c cpp6.c
  1251. END_OF_FILE
  1252. if test 579 -ne `wc -c <'org/make.boot'`; then
  1253.     echo shar: \"'org/make.boot'\" unpacked with wrong size!
  1254. fi
  1255. # end of 'org/make.boot'
  1256. fi
  1257. if test -f 'org/makefile.txt' -a "${1}" != "-c" ; then 
  1258.   echo shar: Will not clobber existing file \"'org/makefile.txt'\"
  1259. else
  1260. echo shar: Extracting \"'org/makefile.txt'\" \(3649 characters\)
  1261. sed "s/^X//" >'org/makefile.txt' <<'END_OF_FILE'
  1262. X# Unix makefile for cpp
  1263. X#
  1264. X# On certain systems, such as Unix System III, you may need to define
  1265. X# $(LINTFLAGS) in the make command line to set system-specific lint flags.
  1266. X#
  1267. X# This Makefile assumes cpp will replace the "standard" preprocessor.
  1268. X# Delete the reference to -DLINE_PREFIX=\"\" if cpp is used stand-alone.
  1269. X# LINEFIX is a sed script filter that reinserts #line -- used for testing
  1270. X# if LINE_PREFIX is set to "".   Note that we must stand on our heads to
  1271. X# match the # and a line had better not begin with $.  By the way, what
  1272. X# we really want is
  1273. X#    LINEFIX = | sed "s/^#/#line/"
  1274. X#
  1275. XCPPDEFINE = -DLINE_PREFIX=\"\"
  1276. XLINEFIX = | sed "s/^[^ !\"%-~]/&line/"
  1277. X#
  1278. X# Define OLD_PREPROCESSOR non-zero to make a preprocessor which is
  1279. X# "as compatible as possible" with the standard Unix V7 or Ultrix
  1280. X# preprocessors.  This is needed to rebuild 4.2bsd, for example, as
  1281. X# the preprocessor is used to modify assembler code, rather than C.
  1282. X# This is not recommended for current development.  OLD_PREPROCESSOR
  1283. X# forces the following definitions:
  1284. X#   OK_DOLLAR        FALSE    $ is not allowed in variables
  1285. X#   OK_CONCAT        FALSE    # cannot concatenate tokens
  1286. X#   COMMENT_INVISIBLE    TRUE    old-style comment concatenation
  1287. X#   STRING_FORMAL    TRUE    old-style string expansion
  1288. X#
  1289. XOLDDEFINE = -DOLD_PREPROCESSOR=1
  1290. X#
  1291. X# DEFINES collects all -D arguments for cc and lint:
  1292. X# Change DEFINES = $(CPPDEFINE) $(OLDDEFINE)
  1293. X# for an old-style preprocessor.
  1294. X# If being used for GNU Emacs, the macro EMACS will be defined as -DEMACS.
  1295. X#
  1296. XDEFINES = $(CPPDEFINE) $(OLDDEFINE) $(EMACS)
  1297. X
  1298. XCFLAGS = -g $(DEFINES)
  1299. X
  1300. X#
  1301. X# ** compile cpp
  1302. X#
  1303. XSRCS = cpp1.c cpp2.c cpp3.c cpp4.c cpp5.c cpp6.c
  1304. XOBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o
  1305. Xcpp: $(OBJS)
  1306. X    $(CC) $(CFLAGS) $(OBJS) -o cpp
  1307. X
  1308. X#
  1309. X# ** Test cpp by preprocessing itself, compiling the result,
  1310. X# ** repeating the process and diff'ing the result.  Note: this
  1311. X# ** is not a good test of cpp, but a simple verification.
  1312. X# ** The diff's should not report any changes.
  1313. X# ** Note that a sed script may be executed for each compile
  1314. X#
  1315. Xtest:
  1316. X    cpp cpp1.c $(LINEFIX) >old.tmp1.c
  1317. X    cpp cpp2.c $(LINEFIX) >old.tmp2.c
  1318. X    cpp cpp3.c $(LINEFIX) >old.tmp3.c
  1319. X    cpp cpp4.c $(LINEFIX) >old.tmp4.c
  1320. X    cpp cpp5.c $(LINEFIX) >old.tmp5.c
  1321. X    cpp cpp6.c $(LINEFIX) >old.tmp6.c
  1322. X    $(CC) $(CFLAGS) old.tmp[123456].c
  1323. X    a.out cpp1.c >new.tmp1.c
  1324. X    a.out cpp2.c >new.tmp2.c
  1325. X    a.out cpp3.c >new.tmp3.c
  1326. X    a.out cpp4.c >new.tmp4.c
  1327. X    a.out cpp5.c >new.tmp5.c
  1328. X    a.out cpp6.c >new.tmp6.c
  1329. X    diff old.tmp1.c new.tmp1.c
  1330. X    diff old.tmp2.c new.tmp2.c
  1331. X    diff old.tmp3.c new.tmp3.c
  1332. X    diff old.tmp4.c new.tmp4.c
  1333. X    diff old.tmp5.c new.tmp5.c
  1334. X    diff old.tmp6.c new.tmp6.c
  1335. X    rm a.out old.tmp[123456].* new.tmp[123456].*
  1336. X
  1337. X#
  1338. X# A somewhat more extensive test is provided by the "clock"
  1339. X# program (which is not distributed).  Substitute your favorite
  1340. X# macro-rich program here.
  1341. X#
  1342. Xclock:    clock.c cpp
  1343. X    cpp clock.c $(LINEFIX) >temp.cpp.c
  1344. X    cc temp.cpp.c -lcurses -ltermcap -o clock
  1345. X    rm temp.cpp.c
  1346. X
  1347. X#
  1348. X# ** Lint the code
  1349. X#
  1350. X
  1351. Xlint:    $(SRCS)
  1352. X    lint $(LINTFLAGS) $(DEFINES) $(SRCS)
  1353. X
  1354. X#
  1355. X# ** Remove unneeded files
  1356. X#
  1357. Xclean:
  1358. X    rm -f $(OBJS) cpp
  1359. X
  1360. X#
  1361. X# ** Rebuild the archive files needed to distribute cpp
  1362. X# ** Uses the Decus C archive utility.
  1363. X#
  1364. X
  1365. Xarchc:    archc.c
  1366. X    $(CC) $(CFLAGS) archc.c -o archc
  1367. X
  1368. Xarchx:    archx.c
  1369. X    $(CC) $(CFLAGS) archx.c -o archx
  1370. X
  1371. Xarchive: archc
  1372. X    archc readme.txt cpp.mem archx.c archc.c cpp.rno makefile.txt \
  1373. X        cpp*.h >cpp1.arc
  1374. X    archc cpp1.c cpp2.c cpp3.c >cpp2.arc
  1375. X    archc cpp4.c cpp5.c cpp6.c >cpp3.arc
  1376. X
  1377. X#
  1378. X# Object module dependencies
  1379. X#
  1380. X
  1381. Xcpp1.o    :    cpp1.c cpp.h cppdef.h
  1382. X
  1383. Xcpp2.o    :    cpp2.c cpp.h cppdef.h
  1384. X
  1385. Xcpp3.o    :    cpp3.c cpp.h cppdef.h
  1386. X
  1387. Xcpp4.o    :    cpp4.c cpp.h cppdef.h
  1388. X
  1389. Xcpp5.o    :    cpp5.c cpp.h cppdef.h
  1390. X
  1391. Xcpp6.o    :    cpp6.c cpp.h cppdef.h
  1392. X
  1393. X
  1394. END_OF_FILE
  1395. if test 3649 -ne `wc -c <'org/makefile.txt'`; then
  1396.     echo shar: \"'org/makefile.txt'\" unpacked with wrong size!
  1397. fi
  1398. # end of 'org/makefile.txt'
  1399. fi
  1400. if test -f 'org/readme' -a "${1}" != "-c" ; then 
  1401.   echo shar: Will not clobber existing file \"'org/readme'\"
  1402. else
  1403. echo shar: Extracting \"'org/readme'\" \(1025 characters\)
  1404. sed "s/^X//" >'org/readme' <<'END_OF_FILE'
  1405. XThis is a version of the Decus cpp which has been modified to run on
  1406. Xthe Amiga.  The bootstraping and porting process is not real straight-
  1407. Xforward, and in fact required the resources of a Unix system cpp since
  1408. Xneither Manx nor Lattice could properly deal with the cpp source code
  1409. Xbefore preprocessing.  Thus, it may require some work and ingenuity
  1410. Xto recreate the supplied executable!
  1411. X
  1412. XThis cpp predefines "amiga" as opposed to "AMIGA".  This is a somewhat
  1413. Xbelated attempt to coerce the Amiga world into following the convention
  1414. Xof other C environments that the system predefines are lowercase to avoid
  1415. Xclashes with user predefines, which are uppercase by convention.
  1416. X
  1417. XA hacked up version of my Unix like cc frontend that knows about the
  1418. Xcpp is also supplied, for the Manx compiler.
  1419. X
  1420. XI was holding this back until I had a copy of the public domain C
  1421. Xcompiler and assembler to go along with it, but since these two items
  1422. Xappear to be unreleasable for the immediate future, decided to go ahead
  1423. Xand release the cpp now.
  1424. X
  1425. X-Fred
  1426. END_OF_FILE
  1427. if test 1025 -ne `wc -c <'org/readme'`; then
  1428.     echo shar: \"'org/readme'\" unpacked with wrong size!
  1429. fi
  1430. # end of 'org/readme'
  1431. fi
  1432. if test -f 'org/readme.txt' -a "${1}" != "-c" ; then 
  1433.   echo shar: Will not clobber existing file \"'org/readme.txt'\"
  1434. else
  1435. echo shar: Extracting \"'org/readme.txt'\" \(4421 characters\)
  1436. sed "s/^X//" >'org/readme.txt' <<'END_OF_FILE'
  1437. X
  1438. XDecus cpp is a public-domain implementation of the C preprocessor.
  1439. XIt runs on VMS native (Vax C), VMS compatibilty mode (Decus C),
  1440. XRSX-11M, RSTS/E, P/OS, and RT11, as well as on several varieties
  1441. Xof Unix, including Ultrix.  Decus cpp attempts to implement features
  1442. Xin the Draft ANSI Standard for the C language.  It should be noted,
  1443. Xhowever, that this standard is under active development:  the current
  1444. Xdraft of the standard explicitly states that "readers are requested
  1445. Xnot to specify or claim conformance to this draft."  Thus readers
  1446. Xand users of Decus cpp should not assume that it conforms to the
  1447. Xdraft standard, or that it will conform to the actual C language
  1448. Xstandard.
  1449. X
  1450. XThese notes describe how to extract the cpp source files, configure it
  1451. Xfor your needs, and mention a few design decisions that may be of interest
  1452. Xto maintainers.
  1453. X
  1454. X            Installation
  1455. X
  1456. XBecause the primary development of cpp was not on Unix, it
  1457. Xis distributed using the Decus C archive program (quite similar
  1458. Xto the archiver published in Kernighan and Plauger's Software
  1459. XTools).  To extract the files from the net.sources distribution,
  1460. Xsave this message as cpp1.arc and the other two distribution
  1461. Xfiles as cpp2.arc and cpp3.arc.  Then, using your favorite editor,
  1462. Xlocate the archx.c program, just following the line beginning with
  1463. X"-h- archx.c" -- the format of the distribution is just:
  1464. X
  1465. X    -h- readme.txt
  1466. X      ... this file
  1467. X    -h- cpp.mem
  1468. X      ... description of cpp
  1469. X    -h- archx.c
  1470. X      ... archx.c program -- extracts archives
  1471. X    -h- archc.c
  1472. X      ... archc.c program -- creates archives
  1473. X
  1474. XCompile archx.c -- it shouldn't require any special editing.
  1475. XThen run it as follows:
  1476. X
  1477. X    archx *.arc
  1478. X
  1479. XYou do not need to remove mail headers from the saved messages.
  1480. X
  1481. XYou should then read through cppdef.h to make sure the HOST and
  1482. XTARGET (and other implementation-specific) definitions are set
  1483. Xcorrectly for your machine, editing them as needed.
  1484. X
  1485. XYou may then copy makefile.txt to Makefile, editing it as needed
  1486. Xfor your particular system.  On Unix, cpp should be compiled
  1487. Xby make without further difficulty.  On other operating systems,
  1488. Xyou should compile the six source modules, linking them together.
  1489. XNote that, on Decus C based systems, you must extend the default
  1490. Xstack allocation.  The Decus C build utility will create the
  1491. Xappropriate command file.
  1492. X
  1493. X            Support Notes
  1494. X
  1495. XThe USENET distribution kit was designed to keep all submissions around
  1496. X50,000 bytes:
  1497. X
  1498. Xcpp1.arc:
  1499. X    readme.txt    This file
  1500. X    cpp.mem        Documentation page (see below)
  1501. X    archx.c        Archive extraction program
  1502. X    archc.c        Archive construction program
  1503. X    cpp.rno        Source for cpp.mem (see below)
  1504. X    makefile.txt    Unix makefile -- copy to Makefile
  1505. X    cpp.h        Main header file (structure def's and globals)
  1506. X    cppdef.h    Configuration file (host and target definitions)
  1507. X
  1508. Xcpp2.arc:
  1509. X    cpp1.c        Mainline code, documentation master sources
  1510. X    cpp2.c        most #control processing
  1511. X    cpp3.c        filename stuff and command line parsing
  1512. Xcpp3.arc:
  1513. X    cpp4.c        #define processor
  1514. X    cpp5.c        #if <expr> processor
  1515. X    cpp6.c        Support code (symbol table and I/O routines)
  1516. X    
  1517. XCpp intentionally does not rely on the presence of a full-scale
  1518. Xmacro preprocessor, it does require the simple parameter substitution
  1519. Xpreprocessor capabilities of Unix V6 and Decus C.  If your C
  1520. Xlanguage lacks full preprocessing, you should make sure "nomacargs"
  1521. Xis #define'd in cpp.h.  (This is done automatically by the Decus C
  1522. Xcompiler.)
  1523. X
  1524. XThe documentation (manual page) for cpp is included as cpp.mem
  1525. Xand cpp.rno.  Cpp.rno is in Dec Runoff format, built by a Decus C
  1526. Xutility (getrno) from original source which is embedded in cpp1.c.
  1527. XTo my knowledge, there is no equivalent program that creates
  1528. Xthe nroff source appropriate for Unix.
  1529. X
  1530. XI would be happy to receive fixes to any problems you encounter.
  1531. XAs I do not maintain distribution kit base-levels, bare-bones
  1532. Xdiff listings without sufficient context are not very useful.
  1533. XIt is unlikely that I can find time to help you with other
  1534. Xdifficulties.
  1535. X
  1536. X            Acknowledgements
  1537. X
  1538. XI received a great deal of help from many people in debugging cpp.
  1539. XAlan Feuer and Sam Kendall used "state of the art" run-time code
  1540. Xcheckers to locate several errors.  Ed Keiser found problems when
  1541. Xcpp was used on machines with different int and pointer sizes.
  1542. XDave Conroy helped with the initial debugging, while Arthur Olsen
  1543. Xand George Rosenberg found (and solved) several problems in the
  1544. Xfirst USENET release.
  1545. X
  1546. XMartin Minow
  1547. Xdecvax!minow
  1548. X
  1549. END_OF_FILE
  1550. if test 4421 -ne `wc -c <'org/readme.txt'`; then
  1551.     echo shar: \"'org/readme.txt'\" unpacked with wrong size!
  1552. fi
  1553. # end of 'org/readme.txt'
  1554. fi
  1555. if test -f 'test.c' -a "${1}" != "-c" ; then 
  1556.   echo shar: Will not clobber existing file \"'test.c'\"
  1557. else
  1558. echo shar: Extracting \"'test.c'\" \(328 characters\)
  1559. sed "s/^X//" >'test.c' <<'END_OF_FILE'
  1560. X#define cat(x, y)   x ## y
  1561. X#define var123        Werkt!!!
  1562. Xcat(var, 123);
  1563. Xcat(cat(1, 2), 3);
  1564. X#define cat2(x, y)  x/**/y
  1565. Xcat2(var, 123);
  1566. Xcat2(cat2(1, 2), 3);
  1567. X#define str(arg)    #arg
  1568. Xstr("Hallo");
  1569. Xstr(Ha"l"lo);
  1570. X#define instr(x)    "x y" "x"
  1571. Xinstr(Dit is de tweede string)
  1572. X#define spaces        a    b    c \
  1573. X        nexy line
  1574. X#define zeroargs()
  1575. END_OF_FILE
  1576. if test 328 -ne `wc -c <'test.c'`; then
  1577.     echo shar: \"'test.c'\" unpacked with wrong size!
  1578. fi
  1579. # end of 'test.c'
  1580. fi
  1581. echo shar: End of archive 1 \(of 5\).
  1582. cp /dev/null ark1isdone
  1583. MISSING=""
  1584. for I in 1 2 3 4 5 ; do
  1585.     if test ! -f ark${I}isdone ; then
  1586.     MISSING="${MISSING} ${I}"
  1587.     fi
  1588. done
  1589. if test "${MISSING}" = "" ; then
  1590.     echo You have unpacked all 5 archives.
  1591.     rm -f ark[1-9]isdone
  1592. else
  1593.     echo You still need to unpack the following archives:
  1594.     echo "        " ${MISSING}
  1595. fi
  1596. ##  End of shell archive.
  1597. exit 0
  1598. -- 
  1599. Submissions to comp.sources.amiga and comp.binaries.amiga should be sent to:
  1600.     amiga@cs.odu.edu    
  1601. or    amiga@xanth.cs.odu.edu    ( obsolescent mailers may need this address )
  1602. or    ...!uunet!xanth!amiga    ( very obsolescent mailers need this address )
  1603.  
  1604. Comments, questions, and suggestions s should be addressed to ``amiga-request''
  1605. (only use ``amiga'' for submissions) at the above addresses.
  1606.